# import PySide6
from PySide6.QtWidgets import QWidget, QFrame, QDialog, QLabel, QProgressBar, QVBoxLayout
from PySide6.QtCore import Qt

from util import UiUtil
from view.TitleBar import TitleBar


class ProgressDlg(QDialog):

    def __init__(self, parent=None):
        """初始化"""
        super().__init__(parent)

        # 设置无边框窗口
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint)

        # 设定组件布局
        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

        # 添加标题
        self.title_bar = TitleBar(self)
        self.title_bar.set_max_button_visible(False)
        self.title_bar.set_min_button_visible(False)
        self.title_bar.set_close_button_visible(False)
        self.title_bar.set_help_button_visible(False)
        layout.addWidget(self.title_bar)

        # 加载界面
        ui = UiUtil.loadUiFile("ui/ProgressDlg.ui")
        layout.addWidget(ui)

        # 绑定控件
        self.info_label: QLabel = ui.info
        self.progress_bar: QProgressBar = ui.progress_bar
        # self.progress_bar.setTextVisible(True)

        # 设置主窗口
        self.setMinimumWidth(400)
        self.setMinimumHeight(120)
        self.resize(400, 120)

    def set_title(self, title: str):
        self.title_bar.set_title(title)

    def set_info(self, text: str):
        self.info_label.setText(text)

    def set_progress(self, progress: int):
        self.progress_bar.setValue(progress)
